extends Node2D
const PLAYER = preload("res://scenes/player.tscn")
const SKILL_UI = preload("res://scenes/skill_ui.tscn")
@onready var left_container: GridContainer = $HBoxContainer/LeftContainer
@onready var right_container: GridContainer = $HBoxContainer/RightContainer
@onready var round_label: Label = $RoundLabel

func _ready() -> void:
	TurnManager.round_end.connect(_on_round_end)

func _on_button_button_down() -> void:
	#var DataManager = DataManager.new()
	for index in 3:
		var player = PLAYER.instantiate()
		player.attributes = DataManager.data.characters["1000"+str(index+1)]
		player.side = Character.LEFT
		left_container.add_child(player)
		player.position.x = index * 100
		TurnManager.characters.append(player)
		for i in 3:
			var skill = Utils.instatiate_class(GlobalVars.skill_class_path,"bing_feng_ling_yu").new(DataManager.data.skills["bing_feng_ling_yu"])
			var skill_ui = SKILL_UI.instantiate()
			skill_ui.skill = skill
			player.append_skill(skill_ui)
	
	for index in 3:
		var player = PLAYER.instantiate()
		player.attributes = DataManager.data.characters["1000"+str(index+1)]
		player.side = Character.RIGHT
		right_container.add_child(player)
		player.position.x = index * 100
		TurnManager.characters.append(player)
		for i in 3:
			var skill = Utils.instatiate_class(GlobalVars.skill_class_path,"bing_feng_ling_yu").new(DataManager.data.skills["bing_feng_ling_yu"])
			var skill_ui = SKILL_UI.instantiate()
			skill_ui.skill = skill
			player.append_skill(skill_ui)


func _on_button_2_button_down():
	TurnManager.start_battle()
	
func _on_round_end(_round:int):
	round_label.text = "第" + str(_round) + "回合"
